home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeeds.ans.net!interaccess!usenet
- From: brianmcg@interaccess.com (Brian V. McGroarty)
- Newsgroups: comp.lang.c
- Subject: Re: Getting date in UNIX
- Date: 18 Mar 1996 18:48:52 GMT
- Organization: Internet Squire
- Message-ID: <4ikb6k$g1e@nntp.interaccess.com>
- References: <4ik447$bn7@raffles.technet.sg>
- Reply-To: brianmcg@interaccess.com
- NNTP-Posting-Host: d51-isdn.nhe.interaccess.com
- X-Newsreader: Internet Squire 1.20
-
- Leonard Sim wrote:
- >Can anyone please inform me how to obtain the date in UNIX C??
- >I just need the date in this format "dd/mm/yyyy". Thanks!!!
-
- Look at "time()" and "ctime()" -- prototyped in time.h.
-
- time_t time(time_t *timer) will fetch the time and day in seconds since
- midnight of Jan 1, 1970 and return them in a variable of type time_t
- (usually a 32-bit integer.)
-
- With the number above, you can convert to the current date yourself, or you
- can look at char *ctime(time_t *time) (probably const time_t *time in
- libraries with stronger types). "ctime()" will convert the seconds into a
- human-readable format, although it is not the format you specifically asked
- for. I also don't know for sure that the format it converts to is standard
- across all systems... on mine I get "Mon Mar 18 12:48:53 1996" with a
- new-line and null terminator.
-
- Be warned that the string ctime points to will be overwritten on subsequent
- local calls to the function -- be sure to copy the data into safe storage
- before running with it!
-
- ---
- Brian Valters McGroarty -- brianmcg@bix.com
- phone/fax (847) 439-7714
-